package com.quanyue.music.file.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.music.domain.entity.QrCode;
import com.quanyue.music.file.service.QrCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "二维码")
@RestController
@RequestMapping("/api")
public class QrCodeController {
    @Autowired
    private QrCodeService qrCodeService;

    @ApiOperation(value = "添加二维码")
    @GetMapping(value = "/qr/code/add", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Boolean> add(@RequestParam("path") String path) {
        qrCodeService.createCode(path);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "二维码列表")
    @GetMapping(value = "/qr/code/select", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <List <QrCode>> codeList() {
        return ServiceResult.success(qrCodeService.selectCode());
    }

    @ApiOperation(value = "删除二维码")
    @GetMapping(value = "/qr/code/delete", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Boolean> deleteQr(@RequestParam("id") String id) {
        qrCodeService.deleteCode(id);
        return ServiceResult.SUCCESS;
    }
}
